//
//  MeViewController.m
//  CleanerAir_Project
//
//  Created by mac on 16/4/28.
//  Copyright © 2016年 Beijing Colin El Internet. All rights reserved.
//

#import "MeViewController.h"
#import "MeTableViewCell.h"
#import "PersonalInformationModel.h"


@interface MeViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    NSArray *_listNameAry;
    NSArray *_viewControllerNameAry;
    
}


@property (weak, nonatomic) IBOutlet UIImageView *meInfoImageView;

@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nickNameLabel;
//个性签名
@property (weak, nonatomic) IBOutlet UILabel *individualitySignatureLabel;


@property (weak, nonatomic) IBOutlet UITableView *listTableView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headImageH;

@end

@implementation MeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.listTableView.dataSource = self;
    self.listTableView.delegate = self;
    
    self.listTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    
    [self initSubArray];
    
    
    [self.meInfoImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(personalInformation)]];
    [self.headImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(personalInformation)]];
    [self.nickNameLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(personalInformation)]];
    [self.individualitySignatureLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(personalElucidation)]];
    
    
    self.headImageH.constant = (kScreenW / 750.0) * 400;
    
//    NSLog(@"%f",self.headImageH.constant);
//    NSLog(@"%f",self.headImageView.height);
  
    self.headImageView.layer.cornerRadius =  kScreenW >= 375 ? self.headImageH.constant * 0.25 : self.headImageView.height * 0.5;
    self.headImageView.layer.borderWidth = 1;
    self.headImageView.layer.borderColor = [UIColor grayColor].CGColor;

}

#pragma mark -- 修改查看 个人信息 & 个人说明
- (void)personalInformation{
    
        UIStoryboard *personalInfo = [UIStoryboard storyboardWithName:@"PersonalInfomation" bundle:nil];
        
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:[personalInfo instantiateInitialViewController] animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    
}

- (void)personalElucidation{
    
}

- (BOOL)isLogin{
    
//    if ([[LoginSingleton sharedLoginSingleton].token isEqualToString:@""] || [LoginSingleton sharedLoginSingleton].token == nil) {
    
        self.headImageView.image = [UIImage imageNamed:@"克林埃尔.png"];
        self.nickNameLabel.text = @"克林埃尔";
        self.individualitySignatureLabel.text = @"您的支持，是我们前进的最大动力！ಠ౪ಠ";
        
//        return NO;
//    }
    
    return YES;
}

#pragma mark -- TableViewDataSource & delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSString *className = _viewControllerNameAry[indexPath.row];
    
    UIViewController *subViewController = [[NSClassFromString(className) alloc] init];
    
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:(UIViewController*)subViewController animated:YES];
    
    self.hidesBottomBarWhenPushed = NO;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listNameAry.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (kScreenW < 375) {
        return  45;
    }
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellid = @"meTableViewCell";
    
    MeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MeTableViewCell" owner:self options:nil] lastObject];
    }
    
    cell.logoImageView.image = [UIImage imageNamed:_listNameAry[indexPath.row]];
    cell.nameLabel.text = _listNameAry[indexPath.row];
    [cell.nameLabel setFont:[UIFont systemFontOfSize:15]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
    
}

#pragma mark -- 初始化列表
- (void)initSubArray{
    _listNameAry = @[@"系统设置"];
     _viewControllerNameAry = @[@"CASystemSettingVC" ];
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = YES;
    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = NO;
    
}

//#pragma mark -- 获取个人信息
//
//- (void)getPerserInfo{
//    
//    [self showIndicator:@"正在加载个人信息，请稍候..."];
//    
//    __weak __typeof(self) weakSelf = self;
//    
//    NSString *urlStr = [NSString stringWithFormat:@"/Api/Member/info?login_token=%@&member_id=%@",[LoginSingleton sharedLoginSingleton].token,[LoginSingleton sharedLoginSingleton].loginModel.ids];
//    
//    [HTTPManager get:GET_URLString(urlStr) success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        [self hideIndicator];
//        if ([responseObject[@"msg"] isEqualToString:@"成功"]) {
//            
//            PersonalInformationModel *model = [[PersonalInformationModel alloc] init];
//            [model setValuesForKeysWithDictionary:responseObject[@"date"]];
//            
////            给单例赋值
//            [LoginSingleton sharedLoginSingleton].perInfoModel = model;
//            
//            //显示
//            [weakSelf accordingToView:model];
//        }
//        
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        [self hideIndicator];
//    }];
//}

//显示到View

- (void)accordingToView:(PersonalInformationModel *)model{
    
    if(model != nil){
    
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [self.headImageView sd_setImageWithURL:[NSURL URLWithString:Get_HeadImage_UrlString(model.avatar)] placeholderImage:[UIImage imageNamed:@"个人注册.png"]];
            
            self.nickNameLabel.text = model.nickname;
            
            self.individualitySignatureLabel.text = model.mood;
            
        });
    
    }
}

#pragma mark -- 登录

- (void)login{
    
   
    
}


#pragma mark -- 三方登录
- (void)thirdPartLoginWithInfo:(NSString *)response withType:(NSString *)loginType{
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
